package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.query.QuestionPageQuery;
import com.tianji.learning.service.IInteractionQuestionService;
import com.tianji.learning.domain.vo.QuestionVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 互动提问的问题表 前端控制器
 * </p>
 *
 * @author lcm
 * @since 2023-07-26
 */
@Api(tags = "问题相关接口")
@Slf4j
@RestController
@RequestMapping("/questions")
@RequiredArgsConstructor
public class InteractionQuestionController {

    private final IInteractionQuestionService iInteractionQuestionService;


    @PostMapping
    @ApiOperation("新增互动问题")
    public void addQuestion(@Valid @RequestBody QuestionFormDTO questionFormDTO){
        iInteractionQuestionService.addQuestion(questionFormDTO);
    }

    @PutMapping("/{id}")
    @ApiOperation("修改互动问题")
    public void updateQuestion(@ApiParam("问题id") @PathVariable Long id,@Valid @RequestBody QuestionFormDTO questionFormDTO){
        iInteractionQuestionService.updateQuestion(id,questionFormDTO);
    }

    @GetMapping("/page")
    @ApiOperation("用户端分页查询")
    public PageDTO<QuestionVO> pageQuery(@ApiParam("问题分页参数") QuestionPageQuery questionPageQuery){
        return iInteractionQuestionService.pageQuery(questionPageQuery);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询问题详情")
    public QuestionVO questionDetails(@ApiParam("问题id") @PathVariable Long id){
        return iInteractionQuestionService.questionDetails(id);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除问题")
    public void deleteQuestion(@ApiParam("问题id") @PathVariable Long id){
        iInteractionQuestionService.deleteQuestion(id);
    }
}
